package com.coderfans.utils;

import java.util.*;

import static java.util.stream.Collectors.toList;

/**
 * Created by ${fanchunshuai} on 2017-7-12.
 *
 * @version: V1.0
 * @Desc:
 * @Copyright (c) 2017 58到家-版权所有
 */
public class DataConvertUtils<T> {
    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add(null);
        list.add("asd");
        list.add("asd");
        list.add("sfdasdf");
        list.add(null);
        DataConvertUtils dataConvertUtils = new DataConvertUtils();
        List<String> list2 = dataConvertUtils.filterSetList8(list);
        System.out.println(list2.toString());

        Set<String> set = dataConvertUtils.filterSetList7(list);
        System.out.println(set.toString());

    }

    /**
     * java 8过滤 list 非空，并且非重复
     * @param list
     * @return
     */
    public  List<T>  filterSetList8(List<T> list){
        return list.stream().filter(t-> t!=null).distinct().collect(toList());
    }

    /**
     * java 7过滤 list 非空，并且非重复
     * @param list
     * @return
     */
    public Set<T> filterSetList7(List<T> list) {
        Set<T> set = new HashSet();
        for (T t : list) {
            if (t != null) {
                set.add(t);
            }
        }
        return set;
    }
}
